﻿using HandyControl.Controls;
using KinTN_WMS_CL.Model;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using Prism.Services.Dialogs;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace KinTN_WMS_CL.UserControlModels
{
    public class MaterialStorageDetailsViewModel : BindableBase, IDialogAware
    {
        private string _locationCode;
        private string _locationName;
        private int _size;
        private bool _checkedYes;
        private bool _checkedNo;
        private readonly IEventAggregator _eventAggregator;

        public string LocationCode
        {
            get => _locationCode;
            set => SetProperty(ref _locationCode, value);
        }

        public string LocationName
        {
            get => _locationName;
            set => SetProperty(ref _locationName, value);
        }

        public int Size
        {
            get => _size;
            set => SetProperty(ref _size, value);
        }

        public bool CheckedYes
        {
            get => _checkedYes;
            set => SetProperty(ref _checkedYes, value);
        }
        public bool CheckedNo
        {
            get => _checkedNo;
            set => SetProperty(ref _checkedNo, value);
        }

        public ICommand CloseCommand { get; }
        public ICommand MinimizeCommand { get; }
        public ICommand MaximizeCommand { get; }

        public ICommand BtnCmm { get; set; }

        private DetailedShowModel _detailedShowModel;
        public DetailedShowModel Data
        {
            get { return _detailedShowModel; }
            set { SetProperty(ref _detailedShowModel, value); }
        }

        string IDialogAware.Title => "";

        public MaterialStorageDetailsViewModel(IEventAggregator eventAggregator)
        {
            CloseCommand = new DelegateCommand(OnDialogClosed);
            BtnCmm = new DelegateCommand(BtnSubmit);
            _eventAggregator = eventAggregator;
        }


        public event Action<IDialogResult> RequestClose;

        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {
            var resultData = new DetailedShowModel
            {
                Title = "Some Title", // 从输入控件中获取数据
                ID = 42 // 从输入控件中获取数据
            };

            var result = new DialogResult(ButtonResult.OK, new DialogParameters { { "ResultModel", resultData } });
            RequestClose?.Invoke(result);

        }
        //启动时进入
        public void OnDialogOpened(IDialogParameters parameters)
        {
            DetailedShowModel detailedShowModel = new DetailedShowModel();
            detailedShowModel.Title = parameters.GetValue<string>("Title");
            Data = detailedShowModel;
        }

        public void BtnSubmit()
        {

            string LocationCodeNew = LocationCode;
            _eventAggregator.GetEvent<NotificationEvent>().Publish(new Message()
            {
                info = "添加成功",
                type = MessageEnum.Success,
            });
        }
    }
}
